package me.leiusual.sharing.ui.home.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import me.leiusual.sharing.R
import me.leiusual.sharing.api.model.storeindex.ProductLink

/**
 * Create by leiusual on 2018/7/24
 */
class HomeLinkAdapter : RecyclerView.Adapter<HomeLinkViewHolder>() {

  private val dataSet = arrayListOf<ProductLink>()

  override fun getItemCount(): Int {
    return dataSet.size
  }

  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): HomeLinkViewHolder {
    val inflater = LayoutInflater.from(parent.context)
    val itemView = inflater.inflate(R.layout.view_holder_home_link, parent, false)
    return HomeLinkViewHolder(itemView)
  }

  override fun onBindViewHolder(holder: HomeLinkViewHolder, position: Int) {
    holder.bind(dataSet[position])
  }

  fun submitList(list: List<ProductLink>) {
    dataSet.clear()
    dataSet.addAll(list)
    notifyDataSetChanged()
  }
}